package exercicios.ex08.view;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class FormComentar
 */
@WebServlet("/formComentar")
public class FormComentar extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FormComentar() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=utf-8");
		
		String idPost = request.getParameter("post");
		
		if (idPost != null && !idPost.equals("")) {
			out.println("<html>\n"+
						"<head>\n"+
						"<meta charset=\"utf-8\">\n"+
						"<title>FaceNote Main Page</title>\n"+
						"</head>\n"+
						"<body>\n"+
						"<h2>Informe o seu nome e o seu comentário</h2>\n");
			out.println("<form action=\"/exemploServlet/comentar\" method=\"post\">\n"+
						"<b>Autor:</b> <input type=\"text\" name=\"autor\"><br>\n"+
						"<b>Status:</b><br/>\n"+
						"<input type=\"text\" size=\"60\" name=\"comentario\" value=\"Escreva um comentário...\"><br>\n"+
						"<input type=\"hidden\" name=\"idPost\" value=\""+idPost+"\"><br>\n"+
						"<input type=\"submit\" value=\"Publicar\">\n"+
						"</form>\n");		
			out.println("</body>\n"+
						"</html>");
			out.close();
		}
	}

}
